package lg.minecraft.plugin.entityclear;

import lg.minecraft.plugin.entityclear.command.*;
import lg.minecraft.plugin.entityclear.config.ClearTaskConfig;
import lg.minecraft.plugin.entityclear.config.MainConfig;
import lg.minecraft.plugin.entityclear.manager.ParserManager;
import lg.minecraft.plugin.entityclear.task.EntityClearTaskExecutor;
import lg.minecraft.plugin.entityclear.util.ComponentUtil;
import lg.minecraft.plugin.library.LGPlugin;
import lg.minecraft.plugin.library.command.HelpCommand;
import lombok.Getter;

public final class LGEntityClear extends LGPlugin {

    @Getter
    private static LGEntityClear instance;

    @Override
    public void onLoad() {
        instance = this;
        ParserManager.INSTANCE.registerEntityRemoverParser("default", ComponentUtil::createDefaultEntityRemover);
        ParserManager.INSTANCE.registerWorldFilterParser("white", ComponentUtil::createWhiteListWorldFilter);
        ParserManager.INSTANCE.registerWorldFilterParser("black", ComponentUtil::createBlackListWorldFilter);
        ParserManager.INSTANCE.registerEntityFilterParser("white", ComponentUtil::createWhiteListEntityFilter);
        ParserManager.INSTANCE.registerEntityFilterParser("black", ComponentUtil::createBlackListEntityFilter);
    }

    @Override
    public void onEnable() {
        MainConfig.INSTANCE.load();
        ClearTaskConfig.INSTANCE.load();
        EntityClearTaskExecutor.INSTANCE.start();
        MainCommand mainCommand = new MainCommand();
        mainCommand.registerSubCommand(new SetCommand());
        mainCommand.registerSubCommand(new HelpCommand());
        mainCommand.registerSubCommand(new InfoCommand());
        mainCommand.registerSubCommand(new ReloadCommand());
        mainCommand.registerSubCommand(new TriggerCommand());
    }

    @Override
    public void onDisable() {
        EntityClearTaskExecutor.INSTANCE.stop();
    }

}
